package com.heaven1949.tmall.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heaven1949.tmall.product.dto.ProductPageQueryDTO;
import com.heaven1949.tmall.product.entity.ProductEntity;
import com.heaven1949.tmall.product.mapper.ProductMapper;
import com.heaven1949.tmall.product.service.IProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 商品信息service接口实现类
 *
 * @author zhangjian
 * @date 2023-03-08 16:28:52
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductEntity> implements IProductService {

    @Override
    public IPage<ProductEntity> pageQuery(IPage page, ProductPageQueryDTO dto) {
        log.info("商品信息-分页查询，req：[{}]", dto);
        return page(page, Wrappers.<ProductEntity>lambdaQuery()
                .like(StringUtils.isNotBlank(dto.getProductName()), ProductEntity::getName, dto.getProductName())
                .orderByDesc(ProductEntity::getCreateTime));
    }

    @Override
    public ProductEntity detail(Long id) {
        log.info("商品信息-明细查询，id：[{}]", id);
        return getById(id);
    }

}